package com.dx.mapper.impl;

import com.dx.domain.Student;
import com.dx.mapper.StudentMapper;
import com.dx.util.MySchoolDbMybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;

/**
 * @ClassName StudentMapperImpl
 * @Description TODO:
 * @Author 12994
 * @Date 2024/10/18 16:10
 * @Version 1.0
 **/
public class StudentMapperImpl implements StudentMapper {
    SqlSession sqlSession;

    @Override
    public ArrayList<Student> listStudentsWithGradeInfo() {
        try {
            sqlSession = MySchoolDbMybatisUtil.getSqlSession();
            return sqlSession.getMapper(StudentMapper.class).listStudentsWithGradeInfo();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            MySchoolDbMybatisUtil.releaseSqlSession(sqlSession);
        }
    }

    @Override
    public ArrayList<Student> listStudentWithSubject() {
        try {
            sqlSession = MySchoolDbMybatisUtil.getSqlSession();
            return sqlSession.getMapper(StudentMapper.class).listStudentWithSubject();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            MySchoolDbMybatisUtil.releaseSqlSession(sqlSession);
        }
    }

    public static void main(String[] args) {
        new StudentMapperImpl().listStudentWithSubject().forEach(System.out::println);
    }
}
